<?php
namespace App\Http\Controllers\Api;

use Illuminate\Routing\Controller;
use Illuminate\Support\Facades\DB;
use Input, Response, Request;
use App\Services\Tool\GeneralTool;
use App\Services\JPush\JPushService;
use App\Services\Tool\Pay\AlipayTool;


class OtherController extends Controller{

    public function __construct(JPushService $jpushService,
                                AlipayTool $alipayTool){
        $this->jpushService = $jpushService;
        $this->alipayTool = $alipayTool;
    }
    //帮助
    public function getHelp(){
        // return view('api.help-center');
    }
    public function getQaDetail(){
        // return view('api.qa-detail');
    }
    public function getOtherDetail(){
        // return view('api.other-detail');
    }
    public function getBuyDetail(){
        // return view('api.buy-detail');
    }

    //溢价
    function overflow(){
        return '';
    }
    //关于我们
    public function getAbout(){
         return view('api.about');
    }

    //售后
    function getService(){
        // return view('api.sales');
    }

    //作品发布
    function getOffer(){
        // return view('api.offer');
    }

    //联系客服
    function getCustomerService(){
        // return view('api.sales');
    }

    //配置参数
    function getConfig(){
        $input  = Request::all();
        $arr['unread']        = isset($input['user_id']) &&
                                is_numeric($input['user_id']) &&
                                $input['user_id'] > 10000 ? $this->jpushService->get_user_message_unread($input) : 0;
        $arr['cert_is_vaild'] = DB::table('configs')
                                ->where(['name' => 'cert_is_vaild', 'state' => 1])
                                ->value('value');
        $arr['cert_is_vaild'] = isset($arr['cert_is_vaild']) ? intval($arr['cert_is_vaild']) : 0;
        $arr['enable_chat']   = DB::table('configs')
                                ->where(['name' => 'enable_chat', 'state' => 1])
                                ->value('value');
        $arr['enable_chat']   = isset($arr['enable_chat']) ? intval($arr['enable_chat']) : 0;
        $arr['apply_withddraw_cycle']   = DB::table('configs')
                                          ->where(['name' => 'apply_withddraw_cycle', 'state' => 1])
                                          ->value('value');
        $arr['apply_withddraw_cycle']   = isset($arr['apply_withddraw_cycle']) ? intval($arr['apply_withddraw_cycle']) : 0;
        $arr['apply_withddraw_cycle_times']   = DB::table('configs')
                                                ->where(['name' => 'apply_withddraw_cycle_times', 'state' => 1])
                                                ->value('value');
        $arr['apply_withddraw_cycle_times']   = isset($arr['apply_withddraw_cycle_times']) ? intval($arr['apply_withddraw_cycle_times']) : 0;
        return response()->json(GeneralTool::createResult($arr,'M00000'));
    }

    //获取安卓最新版本信息
    function getAndroidVersionNow(){
        $result  = DB::table('android_versions')
                   ->where(['state' => 1])
                   ->orderBy('created_at','desc')
                   ->select('version_name',
                            'pakage_size',
                            'update_describe',
                            'download_url',
                            'is_must_update',
                            'update_time',
                            'version_code')
                   ->first();
        $result = isset($result) ? $result : (object)[];
        return response()->json(GeneralTool::createResult($result,'M00000'));
    }

    function feed_back(){
        $input   = Request::all();
        $result = $this->jpushService->feedBack($input);
        return response()->json($result);
    }

    public function test(){
        $input  = Request::all();
        $token  = $this->alipayTool->alipayAuthToken(['code'=>$input['code']]);
//        $token = 'appscrtB6bc169db2b9f473e80a8c99668d0dE69';
        $result = $this->alipayTool->alipayUserInfo(['code'=>$token]);

        dd($result);
        return response()->json(GeneralTool::createResult('','M00000'));
    }
}


